/**
 * Created with JetBrains WebStorm.
 * User: FF
 * Date: 15-9-11
 * Time: 下午5:30
 * To change this template use File | Settings | File Templates.
 */

var scene,camera,render,control,stats;

var init = function()
{
    render = new ECLOUD3D.WebGLRenderer();
    render.setSize(window.innerWidth,window.innerHeight);
    render.setClearColor(0x888888);
    render.shadowMapEnabled = true;
    render.gammaFactor = 1.5;
    render.gammaInput = true;
    document.body.appendChild(render.domElement);
    console.log('init scene');
    scene = new ECLOUD3D.Scene();
    console.log('init camera');
    camera = new ECLOUD3D.PerspectiveCamera(45,window.innerWidth/window.innerHeight,0.1,200000000);
    camera.position.set(0,20,20);
    console.log('init control');
    control = new ECLOUD3D.OrbitControls(camera,render.domElement);
//    control = new ECLOUD3D.FirstPersonControl(render.domElement,scene.children,camera);
    console.log('init Stats');
    stats = new Stats();
    stats.domElement.style.position = 'absolute';
    stats.domElement.style.top = stats.domElement.style.right = '0px';
    document.body.appendChild(stats.domElement);
    console.log('init light');
    scene.add(new ECLOUD3D.AmbientLight(0xffffff));
    var light = new ECLOUD3D.DirectionalLight(0xffffff);
    light.position.set(100,100,100);
    light.castShadow = true;
    light.shadowMapWidth = light.shadowMapHeight = 1024*4;
    light.shadowCameraFar = 100*5;
    light.shadowCameraNear = 100/10;
    light.shadowDarkness = 0.35;
    scene.add(light);

	return;
    var tt = setInterval(function()
    {
		
      //  render.render(scene,camera);
        stats.update();
        control.update();
    },16);
};

var animate = function()
{
    console.log('init render');
    //requestAnimationFrame(animate);
	webkitRequestAnimationFrame(animate);
    render.render(scene,camera);
    console.log('render ended');
    stats.update();
    control.update();
};